﻿
<!--
https://github.com/netnr
https://gitee.com/netnr
https://www.netnr.com
https://zme.ink
-->


<!DOCTYPE html>
<html>
<head>

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />


    <title>Nginx编辑器 脚本服务</title>

    <meta name="keywords" content="netnr NET牛人 Nginx编辑器" />
    <meta name="description" content="Script Services Nginx配置文件格式化" />

</head>
<body>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css' rel='stylesheet' />
<link href='https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/jzjs@2.0.2/2.0.2/jz.min.js'></script>
<link href='https://cdn.jsdelivr.net/gh/netnr/cdn/libs/netnr-nav/1.1.2/netnrnav.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/gh/netnr/cdn/libs/netnr-nav/1.1.2/netnrnav.js' defer async></script>
        <link href="/css/global.css?v=NAI_hOr6ZSg5NjaPo94olMdf7kAXXyp9gYOiuK69lLE" rel="stylesheet" />
        <script src="/js/global.js?v=-UUx_lkaONxBXMxYH5RB2QtqMLBOuqV077SxjKI08E4"></script>
            <!--导航-->
            <button type="button" class="MenuToggle show-in-mobile btn btn-lg btn-warning ml-3 mt-3">
                <span class="fa fa-align-justify"></span>
            </button>
            <div class="netnrnav horizontal">
                <div class="netnrnav-wrapper">
                    <ul>
                        <li><a href="https://www.netnr.com" class="siteIcon"><img src="/favicon.ico" /> 首页</a></li>
                        <li><a href="https://www.netnr.com/gist/discover" title="代码片段"><span class="fa fa-fw fa-file-code-o"></span> Gist</a></li>
                        <li><a href="https://www.netnr.com/run/discover" title="在线运行代码"><span class="fa fa-fw fa-play"></span> Run</a></li>
                        <li><a href="https://www.netnr.com/doc" title="文档管理"><span class="fa fa-fw fa-book"></span> Doc</a></li>
                        <li><a href="https://www.netnr.com/draw/discover" title="绘制"><span class="fa fa-fw fa-paint-brush"></span> Draw</a></li>
                        <li><a href="/" title="ss.js.org"><span class="fa fa-fw fa-wrench"></span> 服务</a></li>
                        <li style="background-image: radial-gradient(ellipse, white, rgb(227, 248, 240))">
                            <!--标题-->
                                <a href='javascript:location.reload(false)' title="Nginx配置文件格式化">
                                    <svg class="titleicon"><use xlink:href="#nginx"></use></svg> Nginx&#x7F16;&#x8F91;&#x5668;
                                </a>
                        </li>
                        <li>
                            <a class="text-muted"><span class="fa fa-fw fa-ellipsis-h"></span></a>
                            <ul>
                                <li><a target="_blank" title="码云" href="https://gitee.com/netnr"><i class="fa fa-fw fa-git"></i> Gitee <sup><i class="fa small fa-external-link"></i></sup></a></li>
                                <li><a target="_blank" title="GitHub" href="https://github.com/netnr"><i class="fa fa-fw fa-github"></i> GitHub <sup><i class="fa small fa-external-link"></i></sup></a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        <div class="min300 mt-3">
            <div class="container-fluid">
    <div class="row">
        <div class="col-sm-12">
            <div class="input-group">
                <div class="input-group-prepend">
                    <button class="btn btn-warning" id="btnFormatterNginxConf" title="Shift+Alt+F 快捷格式化">格式化</button>
                </div>
                <div class="input-group-prepend">
                    <select class="custom-select" id="seindent">
                        <optgroup label="缩进">
                            <option value="    ">4格</option>
                            <option value="  ">2格</option>
                        </optgroup>
                    </select>
                </div>
                <div class="input-group-prepend">
                    <select class="custom-select" id="senewline">
                        <optgroup label="格式化选项">
                            <option value="1">大括号在行尾</option>
                            <option value="2">大括号在行首（新的一行）</option>
                        </optgroup>
                    </select>
                </div>
                <div class="input-group-prepend pt-2 pl-3 text-muted">
                    自动保存，可拖拽文件打开
                </div>
            </div>
        </div>
        <div class="col-md-12 mt-2">
            <div id="ebox" class="border position-relative">
                <textarea class="form-control"></textarea>
                <i class="fa fa-arrows-alt fa-fw me-full-btn" title="Switch the full screen"></i>
            </div>
        </div>
    </div>
</div>

<link href='https://cdn.jsdelivr.net/npm/codemirror@5.60.0/lib/codemirror.min.css' rel='stylesheet' />
<script src='https://cdn.jsdelivr.net/npm/codemirror@5.60.0/lib/codemirror.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/codemirror@5.60.0/mode/nginx/nginx.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/nginxbeautifier@1.0.19/nginxbeautifier.min.js'></script>


<script>
    var ebox = $('#ebox');

    var cme = CodeMirror.fromTextArea(ebox.children()[0], {
        mode: 'nginx',
        lineNumbers: true,
        extraKeys: {
            "Shift-Alt-F": function () {
                $('#btnFormatterNginxConf')[0].click();
            },
            "Shift-Ctrl-F": function () {
                $('#btnFormatterNginxConf')[0].click();
            }
        }
    })
    cme.setValue(ss.lsStr("txt"));
    cme.on("change", function () {
        ss.ls.txt = cme.getValue();
        ss.lsSave();
    });

    $(window).on('load resize', function () {
        cme.setSize("100%", $(this).height() - ebox.offset().top - 15);
    }).click(function (e) {
        var target = e.target || window.event.srcElement;
        if (target.nodeName == "I" && target.className.indexOf('fa-arrows-alt') >= 0) {
            cme.setSize("100%", $(this).height() - ebox.offset().top - 15);
        }
    })

    $('#btnFormatterNginxConf').click(function () {
        var indent = $('#seindent').val();
        modifyOptions({ INDENTATION: indent });
        var cleanLines = clean_lines(cme.getValue());
        var newline = $('#senewline').val();
        if (newline == 1) {
            modifyOptions({ trailingBlankLines: false });
            cleanLines = join_opening_bracket(cleanLines);
        }
        cleanLines = perform_indentation(cleanLines, indent);
        cme.setValue(cleanLines.join("\n"));
    });
</script>
        </div>
</body>
</html>
